/*
 * @Description:
 * @Author: HYH
 * @LastEditors: HYH
 * @LastEditTime: 2022-08-31 15:18:19
 */
import app from './app'
import Tools from '@/utils/Tools'
import lang, { initLang } from './lang'
import Apis from '@/http/api'
import http from '@/http/axios/index'
import Rules from '@/utils/rules'
import viewImg from '@/plugin/viewImage'
import importStyle from './importStyle'
import { mock, Random } from './mock'
/**全局变量的名称 */
type globalKeys =
  | 'app'
  | 'lang'
  | 'Tools'
  | 'http'
  | 'Apis'
  | 'Rules'
  | 'viewImg'
  | 'mock'
  | 'Random'
type IGlobalVars = {
  [key in globalKeys]?: any
}
/**全局变量 总和*/
const globalVars: IGlobalVars = {
  app,
  Tools,
  Apis,
  http,
  Rules,
  lang,
  mock,
  Random,
  viewImg
}

/**初始化系统配置 */
const init = () => {
  // 挂载到 window
  Object.keys(globalVars).forEach(key => {
    window[key as any] = globalVars[key as globalKeys]
  })

  /**
   * 注意❗❗❗❗❗❗
   * 此处要在给window挂载之后  在.ts文件中使用才会拿到值  否则会出现undefined
   */
  initLang()

  //引入样式
  importStyle()
}
export default init
